//
//  CXHUBiMAXNativeAd.m
//  CXHAdSDK-UBiMAX
//
//  Created by 陈坤 on 2025/7/28.
//

#import "CXHUBiMAXNativeAd.h"

@interface CXHUBiMAXNativeAd ()<CXHAdSDKNativeAdDelegate>

@property (nonatomic, strong) CXHAdSDKNativeAd *nativeAd;

@end

@implementation CXHUBiMAXNativeAd

- (void)loadNativeAd:(NSString *)posid controller:(UIViewController *)controller count:(int)count{
    if (_nativeAd == nil) {
        self.nativeAd = [[CXHAdSDKNativeAd alloc]init];
        self.nativeAd.posId = posid;
        self.nativeAd.controller = controller;
        self.nativeAd.delegate = self;
    }
    [self.nativeAd load:count];
}

#pragma mark - price
/**
 获取竞价价格，单位分，为0则表示不支持竞价，开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice{
    return [self.nativeAd getBidPrice];
}
/**
 发送竞价成功上报
 @param price 赢价价格，单位分
 */
- (void)sendWinNotice:(NSInteger)price{
    [self.nativeAd sendWinNotice:price];
}

/**
 发送竞价失败上报
 @param price 赢价价格，单位分
 */
- (void)sendLossNotice:(NSInteger)price{
    [self.nativeAd sendLossNotice:price];
}

#pragma mark - CXHAdSDKNativeAdDelegate
/**
 信息流原生广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)CXH_nativeAdSucessToLoad:(CXHAdSDKNativeAd *)nativeAd
                     adViewArray:(NSArray<__kindof UIView<CXHAdapterNativeAdViewDelegate> *> *)adViewArray{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdSucessToLoad:adViewArray:)]) {
        [self.delegate CXHUBiMAX_nativeAdSucessToLoad:nativeAd adViewArray:adViewArray];
    }
}

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)CXH_nativeAdFailToLoad:(CXHAdSDKNativeAd *)nativeAd
                         error:(NSError *)error{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdFailToLoad:error:)]) {
        [self.delegate CXHUBiMAX_nativeAdFailToLoad:nativeAd error:error];
    }
}

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClicked:(CXHAdSDKNativeAd *)nativeAd
                     adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdClicked:adView:loadingPageURL:)]) {
        [self.delegate CXHUBiMAX_nativeAdClicked:nativeAd adView:adView loadingPageURL:loadingPageURL];
    }
}

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClose:(CXHAdSDKNativeAd *)nativeAd
                   adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdClose:adView:)]) {
        [self.delegate CXHUBiMAX_nativeAdClose:nativeAd adView:adView];
    }
}

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposure:(CXHAdSDKNativeAd *)nativeAd
                      adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdExposure:adView:)]) {
        [self.delegate CXHUBiMAX_nativeAdExposure:nativeAd adView:adView];
    }
}

/**
 信息流广告展示上报
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposureReport:(CXHAdSDKNativeAd *)nativeAd
                            adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdExposureReport:adView:)]) {
        [self.delegate CXHUBiMAX_nativeAdExposureReport:nativeAd adView:adView];
    }
}

/**
 信息流广告点击上报

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClickedReport:(CXHAdSDKNativeAd *)nativeAd
                           adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdClickedReport:adView:)]) {
        [self.delegate CXHUBiMAX_nativeAdClickedReport:nativeAd adView:adView];
    }
}

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdCloseLandingPage:(CXHAdSDKNativeAd *)nativeAd
                              adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    if (self.delegate && [self.delegate respondsToSelector:@selector(CXHUBiMAX_nativeAdCloseLandingPage:adView:)]) {
        [self.delegate CXHUBiMAX_nativeAdCloseLandingPage:nativeAd adView:adView];
    }
}

@end
